package controller

import (
	"github.com/GoAdminGroup/go-admin/context"
	"github.com/GoAdminGroup/go-admin/modules/config"
	"github.com/GoAdminGroup/go-admin/modules/db"
	"github.com/GoAdminGroup/go-admin/plugins/admin/modules/table"
	"github.com/GoAdminGroup/go-admin/template/types"
	"github.com/GoAdminGroup/go-admin/template/types/form"
)

func getDefaultTable(ctx *context.Context) table.Table {
	t := table.NewDefaultTable(ctx, table.DefaultConfigWithDriver(config.DriverMysql))
	return t
}

func getDefaultInfoPanel(t table.Table, disableIdField ...bool) *types.InfoPanel {
	info := t.GetInfo()
	info.HideFilterArea()
	info.SetDefaultPageSize(20)
	info.SetFilterFormLayout(form.LayoutTwoCol)
	if len(disableIdField) > 0 && disableIdField[0] {

	} else {
		info.AddField("ID", "id", db.Int).FieldSortable().FieldFilterable()
	}
	return info
}

func getDefaultFormPanel(t table.Table) *types.FormPanel {
	formList := t.GetForm()
	formList.HideContinueEditCheckBox()
	formList.HideContinueNewCheckBox()
	formList.HideResetButton()

	formList.AddField("ID", "id", db.Int, form.Default).FieldDisableWhenCreate()

	return formList
}
